#include <iostream>
#include <unistd.h>
#include "BlockQueue.hpp"

using namespace std;
using namespace BlockQueueModual;

void *Customer(void *args)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(args);
    while (true)
    {
        int data = 0;
        bq->Pop(&data);
        printf("Custormer get a data %d\n",data);
        sleep(1);
    }
    return nullptr;
}

void *Producer(void *args)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(args);
    int data = 10;

    while (true)
    {
        bq->Push(data);
        data++;
        printf("Producer produce a data %d\n",data);
    }
    return nullptr;
}

int main()
{
    BlockQueue<int> *bq = new BlockQueue<int>(10);

    pthread_t c1,c2,c3, p1,p2;
    pthread_create(&c1, nullptr, Customer, bq);
    pthread_create(&c2, nullptr, Customer, bq);
    pthread_create(&c3, nullptr, Customer, bq);
    pthread_create(&p1, nullptr, Producer, bq);
    pthread_create(&p2, nullptr, Producer, bq);
    pthread_join(c1, nullptr);
    pthread_join(p1, nullptr);
    delete bq;
    return 0;
}